package org.fcitmuk.openclinica;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import org.fcitmuk.db.util.Persistent;


/**
 * This class encapsulates a subject database field value.
 * 
 * @author Daniel
 *
 */
public class SubjectFieldValue implements Persistent{

	private int fieldId;
	private int subjectId;
	private Object value;
	
	public SubjectFieldValue(){
		
	}

	public SubjectFieldValue(int fieldId, int subjectId, Object value) {
		super();
		this.fieldId = fieldId;
		this.subjectId = subjectId;
		this.value = value;
	}
	
	public int getFieldId() {
		return fieldId;
	}

	public void setFieldId(int fieldId) {
		this.fieldId = fieldId;
	}

	public int getSubjectId() {
		return subjectId;
	}

	public void setSubjectId(int subjectId) {
		this.subjectId = subjectId;
	}

	public Object getValue() {
		return value;
	}

	public void setValue(Object value) {
		this.value = value;
	}

	public void read(DataInputStream dis) throws IOException, InstantiationException, IllegalAccessException {
		setFieldId(dis.readInt());
		setSubjectId(dis.readInt());
		setValue(dis.readUTF());
	}
	
	public void write(DataOutputStream dos) throws IOException {
		dos.writeInt(getFieldId());
		dos.writeInt(getSubjectId());
		dos.writeUTF(getValue().toString());
	}
}
